<?php $this->Html->addCrumb('Order Lists'); ?>
<style type="text/css">
    td p span{color:#00B050;}
    td.vendor h2 {font-size:20px; color: #00B050;}
</style>

<div class="global-title">Order lists</div>
<?php if (!empty($carts)): ?>
    <b>Total no. of orders: <?php echo $total; ?><br />
        <?php echo $session->read('Auth.User.first_name') . " " . $session->read('Auth.User.last_name'); ?>'s ($<?php echo $sum['0']['total']; ?>) Purchase history &gt;&gt;</b>
    <table width="100%" border="0" cellspacing="0" cellpadding="0"  id="sold_table" class="tablesorter">
        <thead>
            <tr>
                <th><input type="checkbox" id="select_all" /></th>
                <th>&nbsp;</th>
                <th>Item #</th><th>Title</th><th>Seller ID</th>
                <th>Qty</th><th>Total Price</th><th>Sale Price</th>
                <th>Carrier</th><th>Tracking #</th><th align="center">Action</th>
            </tr>	
        </thead>
        <tbody>
            <?php
            $i = 0;
            foreach ($carts as $cart):
                //print_r($cart);
                $class = 'even';
                if ($i++ % 2 == 0)
                    $class = 'odd';
                ?>
                <tr id="row_<?php echo $cart['Cart']['id']; ?>" class="<?php echo $class; ?>">
                    <td  style="vertical-align: middle;"><input type="checkbox"  id="sold_id" value="<?php echo $cart['Cart']['id']; ?>" /></td>
                    <td  style="vertical-align: middle;">
                        <img src="<?php echo Configure::read('base_url'); ?>/img/thumbs/<?php echo $cart['Product']['products_thumbnailImage']; ?>" alt="<?php echo $cart['Product']['products_title']; ?>" /></td>
                    <td  style="vertical-align: middle;">
                        <a href="<?php echo Configure::read('base_url'); ?>products/details/<?php echo $cart['Product']['id']; ?>" target="_blank" title="<?php echo $cart['Product']['products_title']; ?>"><?php echo $cart['Product']['id']; ?></a>				
                    </td>
                    <td style="vertical-align: middle;"><a href="<?php echo Configure::read('base_url'); ?>products/details/<?php echo $cart['Product']['id']; ?>" target="_blank" title="<?php echo $cart['Product']['products_title']; ?>"><?php echo $cart['Product']['products_title']; ?></a></td>
                    <td style="vertical-align: middle;">
                        
                    <a href="<?php echo Configure::read('base_url'); ?>products/store/<?php echo $cart['Product']['user_id']; ?>">
                    <?php if (isset($cart['Product']['User']['first_name']))
                    echo $cart['Product']['User']['first_name'] . " "; 
                    if (isset($cart['Product']['User']['last_name']))
                    echo $cart['Product']['User']['last_name']; ?>
                    </a>
                    </td>
                    <td style="vertical-align: middle;"><?php echo $cart['Cart']['quantity']; ?></td>
                    <td style="vertical-align: middle;">US $<?php echo ($cart['Cart']['product_cost'] * $cart['Cart']['quantity']); ?></td>
                    <td style="vertical-align: middle;">US $<?php echo $cart['Cart']['product_cost']; ?></td>		
                    <td style="vertical-align: middle;"><?php echo $cart['Shipping']['shipping_method']; ?></td>
                    <td style="vertical-align: middle;"><?php echo $cart['Order']['transaction_id']; ?></td>
                    <td style="vertical-align: top;text-align:right;">
                        <a href="javascript:void(0);" controller="carts" onclick="showPop(this)" action="view_invoice" ElmID="<?php echo $cart['Cart']['id']; ?>">View Invoice</a><br />
                        <a href="javascript:void(0);" controller="products" action="create_dispute" title="create_dispute"
                           ElmID="<?php echo $cart['Cart']['product_id']; ?>" ElmID2="<?php echo $cart['Cart']['id']; ?>" onclick='showPop(this)'>Report a problem</a><br />
                        <a href="javascript:void(0);" controller="products" action="addnote_pending" title="messagebyitem" ElmID="<?php echo $cart['Product']['id']; ?>" ElmID2="<?php echo $cart['Cart']['user_id']; ?>" onclick='showPop(this)'>Add Note</a>
                    </td> 				
                </tr>
                <tr><td colspan="11">&nbsp;</td></tr>
                <?php
                $comments = $this->requestAction('/products/getnote/' . $cart['Cart']['product_id'] . '/' . $cart['Cart']['user_id'] . '/' . '2');
                //pr($comments);
                if (!empty($comments)) {
                    ?>
                    <tr    class="fullrow<?php echo $cart['Cart']['product_id']; ?>" >
                        <td colspan="8" id="disnote<?php echo $cart['Cart']['product_id']; ?>" style="background: none repeat scroll 0pt 0pt BlanchedAlmond;text-align: left;">
                            <?php
                            foreach ($comments as $comment) {
                                echo '<b>' . 'My Note' . ' [ ' . date('d-m-Y g:i A', strtotime($comment['Note']['created'])) . ' ] : </b> ' . $comment['Note']['note'];
                                echo"<br/>";
                                //$j++;
                            }
                            ?>
                        </td></tr>
                    <?php
                }
                ?>

    <?php endforeach; ?>			
        </tbody>		
    </table>
    <br />
    <div class="paging">
        <?php echo $this->Paginator->prev('<< ' . __('previous', true), array(), null, array('class' => 'disabled')); ?> | 
        <?php echo $this->Paginator->numbers(); ?>
        | 
    <?php echo $this->Paginator->next(__('next', true) . ' >>', array(), null, array('class' => 'disabled')); ?>
    </div>
<?php else: ?>
    <br /><br />
    <h2>Your order list is empty.</h2>
    <br /><br /><br />
<?php endif; ?>
<?php echo $this->Html->css('table_css'); ?>
<?php echo $html->script(array("jquery.tablesorter.min.js", "jquery.tablednd.js")); ?>	 
<script type="text/javascript"> 
    jQuery(document).ready(function(){
        //jQuery("#sold_table").tablesorter({headers: { 0:{sorter: false}, 1:{sorter: false}, 2:{sorter: false},3:{sorter: false}, 4:{sorter: false}, 5:{sorter: false},8:{sorter: false},9:{sorter: false},10:{sorter: false},11:{sorter: false}}}); 
        jQuery("#select_all").live('click', function(){
            var checked_status = this.checked;
            jQuery("input[id=sold_id]").each(function()
            {
                this.checked = checked_status;
            });
        });
    });
</script>